package com.potenza.training.dictionary.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.dictionary.dao.HopeStatusDao;
import com.potenza.training.dictionary.entity.HopeStatus;
import com.potenza.training.dictionary.server.HopeStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("hopeStatusServiceImpl")
public class HopeStatusServiceImpl extends ServiceImpl<HopeStatusDao, HopeStatus> implements HopeStatusService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private HopeStatusDao hopeStatusDao;

    @Override
    public List<HopeStatus> findAll() {
        Object hopeStatus = redisTemplate.opsForValue().get("hopeStatus");
        if (hopeStatus==null){
            List<HopeStatus> list = this.list();
            redisTemplate.opsForValue().set("hopeStatus", list);
            return list;
        }

        return (List<HopeStatus>)hopeStatus;
    }
}